package orbitPrototype.input;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import orbitPrototype.Util;
import orbitPrototype.game.Game;

public class MouseInput implements MouseListener, MouseMotionListener 
{
	private Game _game = null;
	
	private boolean _mouseLeftDown = false;
	private boolean _mouseDrags = false;
	private int _mouseX = 0;
	private int _mouseY = 0;
	
	public MouseInput(Game game)
	{
		_game = game;
	}

	@Override
	public void mouseClicked(MouseEvent e)
	{
		_game.mouseClick(e.getX(), e.getY(), e.getButton());
	}

	@Override
	public void mouseEntered(MouseEvent e)
	{
	}

	@Override
	public void mouseExited(MouseEvent e)
	{
	}

	@Override
	public void mouseReleased(MouseEvent e)
	{
		if(e.getButton() == MouseEvent.BUTTON1)
		{
			Util.output("MOUSE UP");
			
			_mouseLeftDown = false;
			_game.mouseUp(e.getX(), e.getY(), e.getButton());
			
			if(_mouseDrags)
			{
				Util.output("END DRAG");
				_mouseDrags = false;
			}
		}
		
	}

	@Override
	public void mousePressed(MouseEvent e)
	{
		if(e.getButton() == MouseEvent.BUTTON1)
		{
			Util.output("MOUSE DAAOWN");
			
			_mouseLeftDown = true;
			
			_game.mouseDown(e.getX(), e.getY(), e.getButton());
		}
	}

	@Override
	public void mouseDragged(MouseEvent e)
	{
		if(!_mouseDrags)
		{
			Util.output("START DRAG");
			_game.primaryMouseDrag(e.getX(), e.getY(), true);
			_mouseDrags = true;
		}
		else
		{
			_game.primaryMouseDrag(e.getX(), e.getY(), false);
		}
		
		_mouseX = e.getX();
		_mouseY = e.getY();
	}

	@Override
	public void mouseMoved(MouseEvent e)
	{
		_game.mouseMove(e.getX(), e.getY());
		_mouseX = e.getX();
		_mouseY = e.getY();
	}
}
